import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 左侧树
export function getPage() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getListAllDepartment',
    method: 'post',
    data: data
  })
}


// 外委左侧单位数据
export function getOutpage() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getListAllInstitutions',
    method: 'post',
    data: data
  })
}
// 数据列表
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    departmentId: queryParams.departmentId, // 培训部门 id
    theType: queryParams.theType // 班组类别 1-内部员工 2-外委人员
  }
  return request({
    url: '/getShiftList',
    method: 'post',
    data: data
  })
}

// 新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId,
      title: val.title, //班组名称
      theType: val.theType, //班组类别 1-内部员工 2-外委人员
      personnelIds: val.personnelIds, //人员名单id列表
      departmentId: val.departmentId, //培训部门 id
      department: val.department, //培训部门
      personnelNames: val.personnelNames, //人员名单（格式：部门-姓名）
      personnelNum: val.personnelNum, //班组人数
      publisherId: val.publisherId, //发布人id
      publisher: val.publisher, //发布人

    }
  }
  return request({
    url: '/addShift',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getShiftData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id
      title: val.title, //班组名称
      theType: val.theType, //班组类别 1-内部员工 2-外委人员
      personnelIds: val.personnelIds, //人员名单id列表
      personnelNames: val.personnelNames, //人员名单（格式：部门-姓名）
      personnelNum: val.personnelNum, //班组人数
      departmentId: val.departmentId, //培训部门 id
      department: val.department, //培训部门
      publisherId: val.publisherId, //发布人id
      publisher: val.publisher, //发布人
    }
  }
  return request({
    url: '/updateShift',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delShift',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleShift',
    method: 'post',
    data: data
  })
}

// 下拉框
export function getSelect() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getShiftComboBox',
    method: 'post',
    data: data
  })
}

// 修改启用状态  enable 启用状态  0-未启用 1-已启用
export function getEnable(theid, enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnableShift',
    method: 'post',
    data: data
  })
}

// 点击 班组名称
export function getPersonnelList(queryParams) {
  const data = {
    theid: queryParams.theid,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
  }
  return request({
    url: '/getPersonnelListShift',
    method: 'post',
    data: data
  })
}

// 单位信息
export function getCompany() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getListAllInstitutions',
    method: 'post',
    data: data
  })
}